add_library(mariadbmon_utils SHARED mariadbmon_utils.cc)
target_link_libraries(mariadbmon_utils maxtest)
set_target_properties(mariadbmon_utils PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs)
install(TARGETS mariadbmon_utils DESTINATION system-test/mariadbmonitor)
add_dependencies(mariadbmon_utils maxtest)

# Two-server multimaster topology
add_test_executable_ex(NAME mdbmon_multimaster_simple SOURCE mdbmon_multimaster_simple.cc
        CONFIG mdbmon_multimaster_simple.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor with Multi-master configurations
add_test_executable_ex(NAME mdbmon_multimaster SOURCE mdbmon_multimaster.cc
        CONFIG mdbmon_multimaster.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor with Multi-master configurations (assume_unique_hostnames=OFF)
add_test_executable_ex(NAME mdbmon_multimaster_serverid ORIG_NAME mdbmon_multimaster
        CONFIG mdbmon_multimaster_serverid.cnf VMS repl_backend LABELS mysqlmon)

# Check that standalone master is allowed. Also, MXS-4301: Allow [mAxScalE]-section
add_test_executable_ex(NAME mdbmon_detect_standalone_master SOURCE mdbmon_detect_standalone_master.cc
        CONFIG mdbmon_detect_standalone_master.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor Failover (automatic) Test
add_test_executable_ex(NAME mdbmon_failover_auto SOURCE mdbmon_failover_auto.cc
        CONFIG mdbmon_failover_auto.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor Failover (manual) Test
add_test_executable_ex(NAME mdbmon_failover_manual SOURCE mdbmon_failover_manual.cc
        CONFIG mdbmon_failover_manual.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor manual failover with many valid candidates
add_test_executable_ex(NAME mdbmon_failover_manual2_4 SOURCE mdbmon_failover_manual2.cc
        CONFIG mdbmon_failover_manual2_4.cnf VMS repl_backend LABELS mysqlmon)
add_test_executable_ex(NAME mdbmon_failover_manual2_3 SOURCE mdbmon_failover_manual2.cc
        CONFIG mdbmon_failover_manual2_3.cnf VMS repl_backend LABELS mysqlmon)
add_test_executable_ex(NAME mdbmon_failover_manual2_2 SOURCE mdbmon_failover_manual2.cc
        CONFIG mdbmon_failover_manual2_2.cnf VMS repl_backend LABELS mysqlmon)

# MariaDB Monitor switchover and related issues (MXS-4605).
add_test_executable_ex(NAME mdbmon_switchover SOURCE mdbmon_switchover.cc
        CONFIG mdbmon_switchover.cnf VMS repl_backend LABELS mysqlmon switchover)

# MXS-4743 switchover-force works even with high replication lag
add_test_executable_ex(NAME mdbmon_switchover_force SOURCE mdbmon_switchover_force.cc
        CONFIG mdbmon_switchover_force.cnf VMS repl_backend LABELS mysqlmon switchover)

# MySQL Monitor switchover with bad master
add_test_executable_ex(NAME mdbmon_switchover_bad_master SOURCE mdbmon_switchover_bad_master.cc
        CONFIG mdbmon_switchover_bad_master.cnf VMS repl_backend LABELS mysqlmon switchover)

# MySQL Monitor manual failover with no valid slaves, uses config of mdbmon_failover_auto. Also MXS-2652.
add_test_executable_ex(NAME mdbmon_failover_no_slaves SOURCE mdbmon_failover_no_slaves.cc
        CONFIG mdbmon_failover_auto.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor Rejoin (good) Test
add_test_executable_ex(NAME mdbmon_rejoin_good SOURCE mdbmon_rejoin_good.cc
        CONFIG mdbmon_rejoin_good.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

add_test_executable_ex(NAME mdbmon_rejoin_bad SOURCE mdbmon_rejoin_bad.cc
        CONFIG mdbmon_rejoin_bad.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor Rejoin (bad2) Test, use template for Rejoin (good)
add_test_executable_ex(NAME mdbmon_rejoin_bad2 SOURCE mdbmon_rejoin_bad2.cc
        CONFIG mdbmon_rejoin_bad.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor Rejoin tests
add_test_executable_ex(NAME mdbmon_rejoin_manual SOURCE mdbmon_rejoin_manual.cc
        CONFIG mdbmon_rejoin_manual.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)
add_test_executable_ex(NAME mdbmon_rejoin_manual2 SOURCE mdbmon_rejoin_manual2.cc
        CONFIG mdbmon_rejoin_manual.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor rolling master
add_test_executable_ex(NAME mdbmon_failover_rolling_master SOURCE mdbmon_failover_rolling_master.cc
        CONFIG mdbmon_failover_rolling_master.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor rejoin old slave
add_test_executable_ex(NAME mdbmon_failover_rejoin_old_slave SOURCE mdbmon_failover_rejoin_old_slave.cc
        CONFIG mdbmon_failover_rejoin_old_slave.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor rolling restart slaves
add_test_executable_ex(NAME mdbmon_failover_rolling_restart_slaves SOURCE mdbmon_failover_rolling_restart_slaves.cc
        CONFIG mdbmon_failover_rolling_restart_slaves.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor failover stress
add_test_executable_ex(NAME mdbmon_failover_stress SOURCE mdbmon_failover_stress.cc
        CONFIG mdbmon_failover_stress.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)
# MySQL Monitor failover stress with semisync
add_test_executable_ex(NAME mdbmon_failover_stress_ss SOURCE mdbmon_failover_stress_ss.cc
        CONFIG mdbmon_failover_stress.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MySQL Monitor switchover stress
add_test_executable_ex(NAME mdbmon_switchover_stress SOURCE mdbmon_switchover_stress.cc
        CONFIG mdbmon_switchover_stress.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# Additional failover + switchover with semisync tests, two MaxScales.
add_test_executable_ex(NAME mdbmon_semisync_fail_switch SOURCE mdbmon_semisync_fail_switch.cc
        CONFIG mdbmon_semisync_fail_switch.cnf VMS repl_backend second_maxscale
        LABELS mysqlmon BREAKS_REPL LIBS mariadbmon_utils)

# Check monitoring and failover with an external master
# Also MXS-5272
add_test_executable_ex(NAME mdbmon_external_master SOURCE mdbmon_external_master.cc
        CONFIG mdbmon_external_master.cnf VMS repl_backend LABELS mysqlmon)

# Check failover, switchover and rejoin with scheduled server events
# Also, MXS-3158, MXS-5948
add_test_executable_ex(NAME mdbmon_fail_switch_events SOURCE mdbmon_fail_switch_events.cc
        CONFIG mdbmon_rejoin_good.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor reset-replication test, use template for Rejoin (good)
add_test_executable_ex(NAME mdbmon_reset_replication SOURCE mdbmon_reset_replication.cc
        CONFIG mdbmon_rejoin_good.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor low disk switchover
# MXS-4917 disk_space_ok-option of master/slave_conditions
add_test_executable_ex(NAME mdbmon_switchover_auto SOURCE mdbmon_switchover_auto.cc
        CONFIG mdbmon_switchover_auto.cnf VMS repl_backend LABELS mysqlmon)

# MySQL Monitor series of failovers and rejoins
add_test_executable_ex(NAME mdbmon_failover_readonly SOURCE mdbmon_failover_readonly.cc
        CONFIG mdbmon_failover_readonly.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MXS-1493: Use replication heartbeat in mysqlmon https://jira.mariadb.org/browse/MXS-1493
add_test_executable_ex(NAME mdbmon_verify_master_failure SOURCE mdbmon_verify_master_failure.cc
        CONFIG mdbmon_verify_master_failure.cnf VMS repl_backend LABELS mysqlmon)

# MariaDB-Monitor enforce_simple_topology
# Also MXS-3324 switchover when autocommit is off on backends.
add_test_executable_ex(NAME mdbmon_enforce_simple SOURCE mdbmon_enforce_simple.cc
        CONFIG mdbmon_enforce_simple.cnf VMS repl_backend LABELS mysqlmon)

add_test_executable_ex(NAME mdbmon_enforce_writable_master SOURCE mdbmon_enforce_writable_master.cc
        CONFIG mdbmon_enforce_writable_master.cnf VMS repl_backend LABELS mysqlmon)

# MariaDB-Monitor multimaster failover/switchover
# MXS-5717 Password encryption with monitor operations
add_test_executable_ex(NAME mdbmon_fail_switch_multi SOURCE mdbmon_fail_switch_multi.cc
        CONFIG mdbmon_fail_switch_multi.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MXS-3018 MariaDB-Monitor master_conditions and slave_conditions
# MXS-5067 enforce_read_only_servers
add_test_executable_ex(NAME mdbmon_master_slave_conditions SOURCE mdbmon_master_slave_conditions.cc
        CONFIG mdbmon_master_slave_conditions.cnf VMS repl_backend LABELS mysqlmon)

# MXS-5366 Rebuild with special chars in username/pw.
# MXS-5717 Password encryption with monitor operations
add_test_executable_ex(NAME mdbmon_rebuild_server SOURCE mdbmon_rebuild_server.cc
        CONFIG mdbmon_rebuild_server.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

# MXS-5366 Rebuild and backup creation with data-at-rest encryption.
add_test_executable_ex(NAME mdbmon_enc_backup SOURCE mdbmon_enc_backup.cc
        CONFIG mdbmon_enc_backup.cnf VMS repl_backend LABELS mysqlmon LIBS mariadbmon_utils)

add_test_executable_ex(NAME mdbmon_prom_dem_files SOURCE mdbmon_prom_dem_files.cc
        CONFIG mdbmon_prom_dem_files.cnf VMS repl_backend LABELS mysqlmon)

add_test_executable_ex(NAME mdbmon_switchover_kill_super SOURCE mdbmon_switchover_kill_super.cc
        CONFIG mdbmon_switchover_kill_super.cnf VMS repl_backend LABELS mysqlmon)

add_test_executable_ex(NAME mdbmon_repl_custom_opts SOURCE mdbmon_repl_custom_opts.cc
        CONFIG mdbmon_repl_custom_opts.cnf VMS repl_backend LABELS mysqlmon)

# Slave with broken replication does not cause new master selection or cannot be selected as master.
# MXS-4798, MXS-4841
add_test_executable_ex(NAME mdbmon_broken_repl_master SOURCE mdbmon_broken_repl_master.cc
        CONFIG mdbmon_broken_repl_master.cnf VMS repl_backend LABELS mysqlmon)

# MXS-4705 Separate private address for servers
add_test_executable_ex(NAME mdbmon_priv_address SOURCE mdbmon_priv_address.cc
        CONFIG mdbmon_priv_address.cnf VMS repl_backend LABELS mysqlmon)

# Two MaxScales with cooperative monitoring. Does not really break replication but mark as such anyway
# to move test exec to a separate MV. Also MXS-4902.
add_test_executable_ex(NAME mdbmon_cooperative_monitoring SOURCE mdbmon_cooperative_monitoring.cc
        CONFIG mdbmon_cooperative_monitoring.cnf1 mdbmon_cooperative_monitoring.cnf2
        VMS repl_backend second_maxscale
        LABELS mysqlmon BREAKS_REPL LIBS mariadbmon_utils)

# Two MaxScales with cooperative monitoring + two MariaDB Servers.
add_test_executable_ex(NAME mdbmon_cooperative_monitoring_2srv SOURCE mdbmon_cooperative_monitoring_2srv.cc
        CONFIG mdbmon_cooperative_monitoring_2srv.cnf VMS repl_backend second_maxscale
        LABELS mysqlmon BREAKS_REPL LIBS mariadbmon_utils)

add_test_executable_ex(NAME mdbmon_servers_no_promotion SOURCE mdbmon_servers_no_promotion.cc
        CONFIG mdbmon_servers_no_promotion.cnf VMS repl_backend)
